﻿namespace ICMRemoteEdu
{
    using System;
    using System.IO;
    using System.Windows.Forms;

    public static class ICMLogger
    {
        public static void WriteLog(string message, LogMode mode)
        {
            switch (mode)
            {
                case LogMode.MessageOnly:
                    MessageBox.Show(message);
                    return;

                case LogMode.FileOnly:
                    WriteToFile(message);
                    return;

                case LogMode.MessageAndFile:
                    WriteToFile(message);
                    MessageBox.Show(message);
                    return;
            }
            throw new ApplicationException("Неивестный тип");
        }

        private static void WriteToFile(string message)
        {
            try
            {
                using (StreamWriter writer = File.AppendText("alert.txt"))
                {
                    writer.WriteLine(string.Format("{0}  {1}", DateTime.Now.ToString(), message));
                    writer.WriteLine();
                    writer.Flush();
                    writer.Close();
                }
            }
            catch
            {
            }
        }

        public enum LogMode
        {
            MessageOnly,
            FileOnly,
            MessageAndFile
        }
    }
}

